package player

import (
	"wanyu/server/engine/globaldef/consts"
	"wanyu/server/engine/logger"
	"wanyu/server/engine/wpcfg"
)

var l *logger.Logger

/**配置文件
{
    "logger" : {
        "player" : {
            "addrs" : [
                "192.168.0.193:9092"
            ],
            "partition":0,
            "maxBytes":0,
            "MaxMsgCnt":0
        }
    }
}*/
//初始化
func Init() {
	var c logger.Config
	wpcfg.ScanNode(consts.ConfigServer, &c, "logger", "player")
	l = logger.NewLogger("player", &c)
	if l == nil {
		panic("create loger failed")
	}
}

//Reg 玩家注册
func Reg(playerID, playerAccount, agentID string, time int64) {
	l.Log(&logData{
		Type:          'r',
		PlayerID:      playerID,
		PlayerAccount: playerAccount,
		AgentID:       agentID,
		Time:          time,
	})
}

//Login 玩家登录
func Login(playerID, playerAccount, agentID string, time int64) {
	l.Log(&logData{
		Type:          'l',
		PlayerID:      playerID,
		PlayerAccount: playerAccount,
		AgentID:       agentID,
		Time:          time,
	})
}

type logData struct {
	Type          int8   `json:"type"`
	PlayerID      string `json:"playerID"`
	PlayerAccount string `json:"playerAccount"`
	AgentID       string `json:"agentID"`
	Time          int64  `json:"time"`
}
